{% extends 'manage/base_manage.html' %}
{% load static %}
{% block title %}Web测试用例步骤编辑{% endblock %}

{% block css %}
    <link rel="stylesheet" href="{% static 'css/web_test/web_step_update.css' %}">
{% endblock %}

{% block content %}
    <div class="content">
        <div id="test_content_apis">
            <h3 id="add_test_name">编辑Web用例步骤</h3>
            <div id="title_apis">
                <form id="web_s_input" method="post" action="">
                    {% csrf_token %}
                    <div class="form-group">
                        <label id='product_name_distance' for="p_name_input">所属用例：</label>
                        <br><br>
                        <select class="form-control" name="dropdown">
                            {% for web_test in web_tests %}
                                {% if web_test.id == web_t_id %}
                                    <option value="{{ web_test.pk }}">
                                        {{ web_test.web_t_name }}
                                    </option>
                                {% endif %}
                            {% endfor %}
                        </select>
                    </div>
                    <div class="form-group">
                        <label id='product_name_distance' for="p_des_input">测试步骤：</label>
                        <br><br>
                        <input name="web_step" type="text" class="form-control" id="p_des_input"
                               placeholder="输入测试步骤" value="{{ web_step.web_step }}">
                        <p id="msg_web_s_name" style="color: red"></p>
                    </div>
                    <div class="form-group">
                        <label id='product_name_distance' for="p_des_input">定位方式：</label>
                        <br><br>
                        <input name="web_find_method" type="text" class="form-control" id="p_des_input"
                               placeholder="输入定位方式" value="{{ web_step.web_find_method }}">
                    </div>
                    <div class="form-group">
                        <label id='product_name_distance' for="p_er_input">控件元素：</label>
                        <br><br>
                        <input name="web_element" type="text" class="form-control" id="p_er_input" placeholder="输入控件元素"
                               value="{{ web_step.web_element }}">
                    </div>
                    <div class="form-group">
                        <label id='product_name_distance' for="p_er_input">操作方法：</label>
                        <br><br>
                        <input name="web_opt_method" type="text" class="form-control" id="p_er_input"
                               placeholder="输入操作方法" value="{{ web_step.web_opt_method }}">
                    </div>
                    <div class="form-group">
                        <label id='product_name_distance' for="p_er_input">测试数据：</label>
                        <br><br>
                        <input name="web_test_data" type="text" class="form-control" id="p_er_input"
                               placeholder="输入测试数据" value="{{ web_step.web_test_data }}">
                    </div>
                    <div class="form-group">
                        <label id='product_name_distance' for="p_er_input">验证数据：</label>
                        <br><br>
                        <input name="web_assert_data" type="text" class="form-control" id="p_er_input"
                               placeholder="输入验证数据" value="{{ web_step.web_assert_data }}">
                    </div>
                    <div class="form-group">
                        <label id='product_name_distance' for="p_er_input">测试结果：</label>
                        <br><br>
                        <select class="form-control" name="web_result">
                            {% if web_step.web_result == 1 %}
                                <option value="1" selected>True</option>
                                <option value="0">False</option>
                            {% elif web_step.web_result == 0 %}
                                <option value="1">True</option>
                                <option value="0" selected>False</option>
                            {% endif %}
                        </select>
                    </div>
                    <button id="btnSubmit" type="button" class="btn">保存</button>
                </form>
            </div>
        </div>
    </div>
{% endblock %}

{% block js %}
    <script>
        toastr.options = {
            closeButton: true,
            timeOut: "1000",
            positionClass: "toast-center-center",
        };

        $(function () {
            btnSubmit();
        });

        function btnSubmit() {
            $("#btnSubmit").click(function () {
                $.ajax({
                    url: "{% url 'atp:web_step_update' web_t_id web_s_id  %}",
                    type: "POST",
                    dataType: "JSON",
                    data: $("#web_s_input").serialize(),
                    success: function (res) {
                        if (res.code === 200) {
                            toastr.success("修改成功");
                            setTimeout(function () {
                                location.href = "{% url 'atp:web_step_manage' web_t_id %}"
                            }, 1000)
                        } else if (res.code === 201) {
                            toastr.success("修改失败");
                            setTimeout(function () {
                                location.href = "{% url 'atp:web_step_manage' web_t_id %}"
                            }, 1000)
                        } else if (res.code === 202) {
                            $("#msg_web_s_name").text("测试步骤内容不能为空")
                        }
                    }
                })
            })
        }
    </script>
{% endblock %}